package cc.wsyw126.java.lintCode;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;


public class BTree {
    BTree left, right;
    public int val;

    public BTree(int val) {
        this.val = val;
        this.left = this.right = null;
    }

    public void beforread() {
        if (this != null) {
            System.out.println(this.val);
            if (this.left != null) this.left.beforread();
            if (this.right != null) this.right.beforread();
        }
    }


    public static void main(String[] args) {
        BTree bt = new BTree(1);
        Queue<BTree> q = new ConcurrentLinkedQueue<BTree>();
        q.add(bt);
        for (int i = 2; i <= 15; i += 2) {
            BTree lf = new BTree(i);
            BTree rt = new BTree(i + 1);
            q.peek().left = lf;
            q.add(lf);
            q.remove().right = rt;
            q.add(rt);
        }
        bt.beforread();


    }

}
